﻿@model SCMS.UI.Models.ReviewPO
@{AjaxOptions ajaxOpts = new AjaxOptions
  {
      UpdateTargetId = "popup-page",
      LoadingElementId = "popup-loading",
      HttpMethod = "Post",
      Url = Url.Action("AuthorizePO"),
      OnBegin = "return VerifyBLBalance(" + Model.POItems.Count + ")",
      OnSuccess = "CenterPopup();LoadRequests();"
  };}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<div class="partialViewCard" style="max-width: 1000px;">
    <div class="partialViewCardHeader"><h3>Purchase Order Authorization</h3></div>
    <br />
    @using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form" }))
    {
        @Html.ValidationSummary(true)
        <h4 style="text-align: center;">@Model.ViewPO.POEntiy.RefNumber</h4>
        <table width="98%" align="center">
            <tr class="gridheader">
                <th width="25%">
                    Purchase Order No.
                </th>
                <th width="25%">
                    Quotation Ref
                </th>
                <th width="25%">
                    Tender Analysis No.
                </th>
                <th width="25%">
                    Order Request No.
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Model.ViewPO.POEntiy.RefNumber
                    @Html.HiddenFor(m => m.ViewPO.POEntiy.Id)
                    @Html.HiddenFor(m => m.ViewPO.deleliveryDate)
                </td>
                <td align="center">
                    @Model.ViewPO.POEntiy.QuotationRef
                </td>
                <td align="center">
                    @if (Model.ViewPO.POEntiy.TenderAnalysi == null)
                    { @Html.Raw("Single Quote")}
                    else
                    {@Model.ViewPO.POEntiy.TenderAnalysi.RefNumber }
                </td>
                <td align="center">
                    @Model.ViewPO.POEntiy.OrderRequest.RefNumber
                </td>
            </tr>
            <tr class="gridheader">
                <th>
                    Date
                </th>
                <th>
                    Payment Terms
                </th>
                <th>
                    Shipping Terms
                </th>
                <th>
                    Delivery Date
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Model.ViewPO.POEntiy.PreparedOn.Value.ToString("dd/MM/yyyy")
                </td>
                <td align="center">
                    @Model.ViewPO.paymentTerm
                </td>
                <td align="center">
                    @Model.ViewPO.shippingTerm
                </td>
                <td align="center">
                    @Model.ViewPO.POEntiy.LatestDeliveryDate.ToString("dd/MM/yyyy")
                </td>
            </tr>
            <tr class="gridheader">
                <th>
                    To Supplier
                </th>
                <th>
                    Delivery Address
                </th>
                <th >
                    Project No
                </th>
                <th colspan="2">
                    DRC Remarks
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Model.ViewPO.supplier
                </td>
                <td align="center">
                    @Model.ViewPO.POEntiy.Location.Name
                </td>
                <td align="center">
                    @Model.ViewPO.POEntiy.OrderRequest.ProjectDonor.ProjectNumber
                </td>
                <td align="center">
                    @Model.ViewPO.POEntiy.Remarks
                </td>
            </tr>
        </table>
        <h4>
            &nbsp;&nbsp;Purchase Order Items</h4>
        <p id="budgetCheckStatus">
        </p>
        <input type="hidden" id="extraUrl" name="extraUrl" value="&PurchaseOrderId=@Model.ViewPO.POEntiy.Id" />
        <table width="98%" align="center" align="center" border="1" style="border: 1px solid grey;
            border-collapse: collapse; font-size: 12px;">
            <tr class="gridheader">
                <th width="3%">
                    No.
                </th>
                <th width="12%">
                    Item
                </th>
                <th width="17%">
                    Description
                </th>
                <th width="7%">
                    Unit
                </th>
                <th width="7%">
                    Qty
                </th>
                <th width="12%">
                    Est. Unit Price
                </th>
                <th width="12%">
                    Est. Total Price
                </th>
                <th width="10%">
                    PN
                </th>
                <th width="10%">
                    BL
                </th>
                <th width="10%">
                    Remarks
                </th>
            </tr>
            @{int num = 0; string pbDiv = ""; string rowId = "";}
            @for (int i = 0; i < Model.POItems.Count; i++)
            {
                num = i + 1;
                pbDiv = "PBlines" + num;
                rowId = "row" + i;
                <tr class="gridodd" id="@rowId">
                    <td align="right">
                        @num
                    </td>
                    <td>
                        @Html.DisplayFor(item => Model.POItems[i].ItemName)
                        @Html.HiddenFor(item => Model.POItems[i].POItemId)
                    </td>
                    <td>
                        @Html.DisplayFor(item => Model.POItems[i].EntityPOItem.OrderRequestItem.ItemDescription)
                    </td>
                    <td>@Html.DisplayFor(item => Model.POItems[i].UnitOfMeasure)
                    </td>
                    <td>@Html.TextBoxFor(item => Model.POItems[i].Quantity, new { @class = "numericTb", @id = "qty" + i, onblur = "calculateTotals(" + i + ", " + Model.POItems.Count + ")" })
                    </td>
                    <td>@Html.TextBoxFor(item => Model.POItems[i].UnitCost, new { @class = "numericTb", @id = "unitPrice" + i, onblur = "calculateTotals(" + i + ", " + Model.POItems.Count + ")" })
                    </td>
                    <td>@Html.TextBoxFor(item => Model.POItems[i].TotalCost, new { @class = "numericTb", @id = "totalPrice" + i, @readonly = "readonly" })
                    </td>
                    @*<td>@Html.DropDownListFor(item => Model.POItems[i].ProjectDonorId, Model.POItems[i].ProjectDonors, new { @class = "smallControl", @onchange = "onChangeProjectNoForPO(this," + num + ")" })</td>*@
                    <td align="center">
                        @Model.POItems[i].EntityPOItem.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber
                    </td>
                    <td>
                        <div id="@pbDiv">
                            @Html.DropDownListFor(item => Model.POItems[i].BudgetLineId, Model.POItems[i].BudgetLines, new { @class = "smallControl", onchange = "javascript:checkBalance4Review(this)" })
                        </div>
                    </td>
                    <td>@Html.TextBoxFor(item => Model.POItems[i].Remarks, new { @class = "smallControl", @readonly = "readonly" })
                    </td>
                </tr>
            }
            <tr>
                <td colspan="4" class="gridheader3" align="right">
                    Currency of Purchase Order:&nbsp;
                </td>
                <td align="center">
                    @Model.ViewPO.POEntiy.Currency.ShortName
                    <input type="hidden" id="currencyId" value="@Model.ViewPO.POEntiy.Currency.Id.ToString()" />
                </td>
                <td class="gridheader3" align="right">
                    Total:&nbsp;
                </td>
                <td>@Html.TextBoxFor(m => m.ViewPO.POEntiy.TotalAmount, new { @class = "numericTb", @readonly = "readonly", @id = "totalVal" })
                </td>
                <td colspan="4" class="gridheader3">
                    PO Value
                </td>
            </tr>
            <tr>
                <td colspan="4" class="gridheader3" align="right">
                    Master Budget Currency:&nbsp;
                </td>
                <td align="center">@Html.DropDownListFor(item => Model.MBCurrencyId, Model.Currencies, new { @class = "smallControl", @id = "mbCurrencyId", @onchange = "calculateMBValue()", @disabled = "disabled" })
                </td>
                <td class="gridheader3" align="right">
                    Total:&nbsp;
                </td>
                <td>
                    @Html.TextBoxFor(item => Model.MbValue, new { @class = "numericTb", @id = "mbValue", @readonly = "readonly" })
                    <input type="hidden" id="origLocalValue" />
                    <input type="hidden" id="origFxValue" />
                </td>
                <td colspan="4" class="gridheader3">
                    PO Value
                </td>
            </tr>
            <tr>
                <td colspan="11" align="center">
                    Additional Remarks
                </td>
            </tr>
            <tr>
                <td colspan="11">@Html.TextAreaFor(item => Model.ViewPO.POEntiy.AdditionalRemarks, new { @class = "expandedTextArea" })
                </td>
            </tr>
        </table>
        <br />
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
            <tr class="gridheader">
                <td width="19%">
                    Authorization
                </td>
                <td width="27%">
                    Authorized Requestor or Unit
                </td>
                <td width="27%">
                    Finance Review/Approval of BL/PN
                </td>
                <td width="27%">
                    Authorized by Manager/CD
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Name:
                </td>
                <td>
                    @if (Model.ViewPO.POEntiy.Staff1 != null)
                    {
                        @Model.ViewPO.POEntiy.Staff1.Person.FirstName 
                        @Html.Raw("&nbsp;")
                        @Model.ViewPO.POEntiy.Staff1.Person.OtherNames
                    }
                </td>
                <td>
                @if (Model.ViewPO.POEntiy.Staff2 != null)
                {
                    @Model.ViewPO.POEntiy.Staff2.Person.FirstName 
                    @Html.Raw("&nbsp;")
                    @Model.ViewPO.POEntiy.Staff2.Person.OtherNames
                }   
            </td>
            <td>
                @if (Model.ViewPO.POEntiy.Staff != null)
                {
                    @Model.ViewPO.POEntiy.Staff.Person.FirstName 
                    @Html.Raw("&nbsp;")
                    @Model.ViewPO.POEntiy.Staff.Person.OtherNames
                }   
            </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Title:
                </td>
                <td>
                    @if (Model.ViewPO.POEntiy.Staff1 != null)
                    {
                        @Model.ViewPO.POEntiy.Staff1.Designation.Name
                    }
                </td>
                <td>
                    @if (Model.ViewPO.POEntiy.Staff2 != null)
                    {
                        @Model.ViewPO.POEntiy.Staff2.Designation.Name
                    }   
                </td>
                <td>
                    @if (Model.ViewPO.POEntiy.Staff != null)
                    {
                        @Model.ViewPO.POEntiy.Staff.Designation.Name
                    }   
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Date:
                </td>
                <td>
                    @if (Model.ViewPO.POEntiy.Staff1 != null)
                    {
                        @Model.ViewPO.POEntiy.PreparedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                    }
                </td>
                <td>
                    @if (Model.ViewPO.POEntiy.Staff2 != null)
                    {
                        @Model.ViewPO.POEntiy.ReviewedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                    }
                </td>
                <td>
                    @if (Model.ViewPO.POEntiy.Staff != null)
                    {
                        @Model.ViewPO.POEntiy.AuthorizedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                    }
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Signature:
                </td>
                <td>
                @if (Model.ViewPO.POEntiy.Staff1 != null)
                {
                    if (Model.ViewPO.POEntiy.Staff1.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.ViewPO.POEntiy.Staff1.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                }
            </td>
            <td>
                @if (Model.ViewPO.POEntiy.Staff2 != null && Model.ViewPO.POEntiy.Staff2.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.ViewPO.POEntiy.Staff2.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                }
            </td>
            <td>
                @if (Model.ViewPO.POEntiy.Staff != null && Model.ViewPO.POEntiy.Staff.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.ViewPO.POEntiy.Staff.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                }
            </td>
            </tr>
            <tr>
                <td colspan="4" align="center">
                    <input type="submit" class="btn green" value="Authorize" />
                    &nbsp;
                    <input type="button" class="btn green" value=" Reject " onclick="sendRequest('/RequestReview/LoadRejectPO/@Model.ViewPO.POEntiy.Id', 'popup-page', 'popup-loading'); CenterPopup();" />
                </td>
            </tr>
        </table>
    }
    <br />
</div>